Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./year2.RDS")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2021-06-30"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2021-06-30"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "mean_total_copies",
## "sd_total_copies", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.3, n = 281)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 11.51063 11.55179 11.59247 11.63269 11.67246 11.71180 11.75072 11.78924
## [9] 11.82738 11.86516 11.90259 11.93969 11.97646 12.01291 12.04898 12.08466
## [17] 12.11992 12.15473 12.18908 12.22294 12.25651 12.28994 12.32314 12.35602
## [25] 12.38848 12.42043 12.45179 12.48246 12.51234 12.54216 12.57245 12.60280
## [33] 12.63283 12.66215 12.69037 12.71709 12.74358 12.77113 12.79935 12.82786
## [41] 12.85629 12.88426 12.91140 12.93732 12.96166 12.98402 13.00404 13.02133
## [49] 13.03862 13.05796 13.07801 13.09742 13.11483 13.12890 13.13828 13.14472
## [57] 13.15065 13.15575 13.15971 13.16221 13.16291 13.16151 13.15768 13.15111
## [65] 13.14014 13.12426 13.10485 13.08331 13.06100 13.03932 13.01965 12.99792
## [73] 12.96993 12.93681 12.89973 12.85981 12.81821 12.77608 12.73456 12.69480
## [81] 12.65795 12.62515 12.59755 12.57059 12.54003 12.50751 12.47466 12.44314
## [89] 12.41457 12.39060 12.36954 12.34870 12.32826 12.30836 12.28918 12.27088
## [97] 12.25360 12.23753 12.22280 12.21013 12.19973 12.19104 12.18351 12.17657
## [105] 12.16968 12.16227 12.15537 12.15024 12.14667 12.14446 12.14340 12.14329
## [113] 12.14392 12.14509 12.14659 12.14822 12.14977 12.15105 12.15328 12.15743
## [121] 12.16288 12.16900 12.17519 12.18080 12.18524 12.18963 12.19538 12.20226
## [129] 12.21003 12.21846 12.22731 12.23633 12.24531 12.25400 12.26217 12.26957
## [137] 12.27598 12.28117 12.28488 12.28649 12.28580 12.28325 12.27929 12.27436
## [145] 12.26891 12.26339 12.25823 12.25388 12.25078 12.24938 12.25013 12.25346
## [153] 12.25983 12.26549 12.26762 12.26798 12.26836 12.27054 12.27628 12.28738
## [161] 12.30296 12.32070 12.34016 12.36089 12.38247 12.40444 12.42638 12.44785
## [169] 12.46840 12.49360 12.52805 12.56984 12.61711 12.66796 12.72050 12.77286
## [177] 12.82315 12.86947 12.90996 12.94271 12.96584 12.98504 13.00677 13.03029
## [185] 13.05489 13.07982 13.10437 13.12781 13.14940 13.16843 13.18415 13.19585
## [193] 13.20280 13.20426 13.19952 13.18639 13.16480 13.13719 13.10600 13.07366
## [201] 13.04260 13.01527 12.98681 12.95142 12.91007 12.86375 12.81345 12.76016
## [209] 12.70485 12.64853 12.59216 12.53674 12.48325 12.43268 12.38601 12.34424
## [217] 12.30392 12.26144 12.21751 12.17285 12.12817 12.08418 12.04159 12.00111
## [225] 11.96346 11.92606 11.88668 11.84645 11.80656 11.76816 11.73243 11.70052
## [233] 11.67049 11.63985 11.60900 11.57829 11.54811 11.51884 11.49084 11.46450
## [241] 11.44019 11.41828 11.39916 11.38319 11.36926 11.35622 11.34443 11.33423
## [249] 11.32597 11.32002 11.31671 11.31559 11.31603 11.31809 11.32182 11.32729
## [257] 11.33454 11.34365 11.35467 11.36767 11.38247 11.39893 11.41708 11.43699
## [265] 11.45872 11.48231 11.50783 11.53524 11.56447 11.59552 11.62839 11.66307
## [273] 11.69958 11.73790 11.77804 11.81999 11.86375 11.90933 11.95672 12.00592
## [281] 12.05693
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./site_objects/wrf_a_year2.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.3, n = 281)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 10.73199 10.82240 10.91104 10.99790 11.08296 11.16619 11.24759 11.32713
## [9] 11.40479 11.48056 11.55441 11.62634 11.69632 11.76435 11.83049 11.89476
## [17] 11.95721 12.01785 12.07672 12.13386 12.18906 12.24214 12.29321 12.34235
## [25] 12.38967 12.43526 12.47922 12.52164 12.56262 12.60161 12.63818 12.67261
## [33] 12.70518 12.73616 12.76584 12.79449 12.82126 12.84527 12.86675 12.88596
## [41] 12.90314 12.91853 12.93239 12.94495 12.95646 12.96716 12.97731 12.98714
## [49] 12.99337 12.99384 12.99041 12.98500 12.97949 12.97577 12.97573 12.97711
## [57] 12.97664 12.97472 12.97173 12.96806 12.96411 12.96028 12.95694 12.95449
## [65] 12.95332 12.95313 12.95329 12.95316 12.95212 12.94954 12.94478 12.93830
## [73] 12.93099 12.92289 12.91402 12.90442 12.89411 12.88314 12.87152 12.85929
## [81] 12.84649 12.83314 12.81927 12.80444 12.78840 12.77150 12.75406 12.73643
## [89] 12.71893 12.70192 12.68594 12.67100 12.65659 12.64220 12.62732 12.61145
## [97] 12.59407 12.57469 12.55279 12.52695 12.49705 12.46447 12.43060 12.39684
## [105] 12.36456 12.33517 12.30375 12.26551 12.22204 12.17495 12.12582 12.07626
## [113] 12.02785 11.98220 11.94089 11.90553 11.87770 11.85901 11.84519 11.83140
## [121] 11.81837 11.80681 11.79743 11.79098 11.78815 11.78939 11.79437 11.80268
## [129] 11.81391 11.82764 11.84346 11.86095 11.87970 11.89929 11.91931 11.93935
## [137] 11.95899 11.97781 11.99541 12.01485 12.03901 12.06721 12.09877 12.13300
## [145] 12.16922 12.20673 12.24485 12.28290 12.32019 12.35604 12.38976 12.42066
## [153] 12.44806 12.47411 12.50110 12.52862 12.55624 12.58354 12.61008 12.63544
## [161] 12.65852 12.67889 12.69718 12.71400 12.72994 12.74563 12.76168 12.77869
## [169] 12.79728 12.81867 12.84323 12.87026 12.89906 12.92892 12.95916 12.98908
## [177] 13.01796 13.04512 13.06986 13.09148 13.10928 13.12611 13.14490 13.16511
## [185] 13.18619 13.20757 13.22872 13.24908 13.26809 13.28520 13.29987 13.31153
## [193] 13.31964 13.32365 13.32300 13.31825 13.31064 13.30056 13.28843 13.27468
## [201] 13.25971 13.24395 13.22618 13.20511 13.18104 13.15430 13.12517 13.09397
## [209] 13.06100 13.02658 12.99099 12.95457 12.91759 12.88039 12.84325 12.80649
## [217] 12.76601 12.71872 12.66647 12.61107 12.55438 12.49821 12.44441 12.39481
## [225] 12.35124 12.30785 12.25910 12.20725 12.15456 12.10331 12.05578 12.01421
## [233] 11.97567 11.93599 11.89558 11.85487 11.81431 11.77432 11.73533 11.69778
## [241] 11.66208 11.62868 11.59799 11.57047 11.54576 11.52307 11.50216 11.48277
## [249] 11.46464 11.44753 11.43118 11.41628 11.40352 11.39262 11.38334 11.37541
## [257] 11.36857 11.36256 11.35711 11.35197 11.34764 11.34475 11.34318 11.34280
## [265] 11.34351 11.34519 11.34772 11.35117 11.35569 11.36128 11.36796 11.37572
## [273] 11.38458 11.39454 11.40560 11.41778 11.43108 11.44550 11.46105 11.47774
## [281] 11.49558
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./site_objects/wrf_b_year2.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.3, n = 281)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 10.84456 10.90662 10.96760 11.02750 11.08628 11.14391 11.20037 11.25563
## [9] 11.30967 11.36246 11.41396 11.46417 11.51304 11.56065 11.60710 11.65241
## [17] 11.69658 11.73963 11.78157 11.82240 11.86191 11.89996 11.93664 11.97207
## [25] 12.00634 12.03957 12.07186 12.10332 12.13406 12.16283 12.18882 12.21273
## [33] 12.23527 12.25714 12.27906 12.30175 12.32483 12.34744 12.36953 12.39103
## [41] 12.41190 12.43208 12.45150 12.47012 12.48788 12.50472 12.52058 12.53542
## [49] 12.55113 12.56887 12.58746 12.60571 12.62243 12.63646 12.64660 12.65348
## [57] 12.65863 12.66224 12.66447 12.66549 12.66549 12.66462 12.66308 12.66102
## [65] 12.65740 12.65143 12.64372 12.63485 12.62541 12.61601 12.60723 12.59763
## [73] 12.58559 12.57144 12.55551 12.53815 12.51967 12.50041 12.48071 12.46090
## [81] 12.44131 12.42227 12.40412 12.38296 12.35618 12.32606 12.29488 12.26492
## [89] 12.23846 12.21778 12.19978 12.18025 12.15980 12.13902 12.11852 12.09890
## [97] 12.08076 12.06471 12.05134 12.04108 12.03339 12.02745 12.02242 12.01749
## [105] 12.01181 12.00457 11.99686 11.99026 11.98457 11.97964 11.97529 11.97135
## [113] 11.96765 11.96402 11.96029 11.95628 11.95183 11.94677 11.94191 11.93802
## [121] 11.93488 11.93227 11.92997 11.92775 11.92539 11.92311 11.92124 11.91969
## [129] 11.91836 11.91717 11.91602 11.91482 11.91349 11.91194 11.91007 11.90780
## [137] 11.90504 11.90168 11.89766 11.89132 11.88155 11.86908 11.85461 11.83886
## [145] 11.82253 11.80635 11.79103 11.77728 11.76581 11.75734 11.75259 11.75225
## [153] 11.75705 11.76508 11.77405 11.78410 11.79540 11.80810 11.82234 11.83827
## [161] 11.85725 11.87996 11.90556 11.93324 11.96216 11.99150 12.02042 12.04811
## [169] 12.07373 12.10196 12.13715 12.17794 12.22298 12.27093 12.32043 12.37014
## [177] 12.41870 12.46478 12.50701 12.54406 12.57456 12.60389 12.63762 12.67476
## [185] 12.71432 12.75530 12.79671 12.83755 12.87684 12.91357 12.94676 12.97540
## [193] 12.99851 13.01508 13.02413 13.02580 13.02177 13.01342 13.00210 12.98916
## [201] 12.97596 12.96385 12.94994 12.93080 12.90705 12.87933 12.84822 12.81437
## [209] 12.77838 12.74086 12.70244 12.66373 12.62535 12.58792 12.55204 12.51834
## [217] 12.48151 12.43720 12.38753 12.33458 12.28045 12.22724 12.17703 12.13193
## [225] 12.09403 12.05599 12.01115 11.96258 11.91337 11.86662 11.82541 11.79282
## [233] 11.76652 11.74205 11.71939 11.69849 11.67931 11.66182 11.64598 11.63174
## [241] 11.61908 11.60794 11.59830 11.59011 11.58781 11.59373 11.60471 11.61759
## [249] 11.62920 11.63637 11.63595 11.63172 11.62926 11.62815 11.62793 11.62817
## [257] 11.62843 11.62826 11.62723 11.62488 11.62232 11.62069 11.61968 11.61896
## [265] 11.61819 11.61705 11.61522 11.61285 11.61034 11.60767 11.60487 11.60194
## [273] 11.59887 11.59568 11.59237 11.58895 11.58541 11.58177 11.57802 11.57418
## [281] 11.57024
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./site_objects/wrf_c_year2.rda")
keeping in case
#save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
#save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
#save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
#save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
#save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
#save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
#save(both_ymina, file = "./plotly_objs/both_ymina.rda")
#save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
#save(both_yminb, file = "./plotly_objs/both_yminb.rda")
#save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
#save(both_yminc, file = "./plotly_objs/both_yminc.rda")
#save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")